package Buildings.office;
import Interfaces.*;
import Errors.*;
public class Office implements Space, java.io.Serializable, Cloneable{
    static private double DEFAULT_AREA=250;
    static private int DEFAULT_ROOM=1;
    private double area;
    private int rooms;
    
    @Override
    public int getHowMuchRooms(){
        return rooms;
    }
    @Override
    public void setRooms(int n){
        try{
        if(n<=0)throw new InvalidRoomsCountException();
        rooms=n;
        }catch(InvalidRoomsCountException e){
            System.out.println(e); 
        }
    }
    @Override
    public double getHowMuchArea(){
        return area;
    }
    @Override
    public void setArea(double s){
        try{
        if(s<=0)throw new InvalidSpaceAreaException();
        area=s;
        }catch(InvalidSpaceAreaException e){
            System.out.println(e);
        }
    }

    public String toString(){
        return " офис: s="+area+" k="+rooms+" |";
    }
    public boolean equals(Object o){
        boolean answer=false;
        if(o.getClass()==this.getClass()){
            if(((Office)o).getHowMuchArea()==this.area && ((Office)o).getHowMuchRooms()==this.rooms){
                answer=true;
            }
        }
        return answer;
    }
    public int hashCode(){
        int hash=(int)(Integer.bitCount(this.rooms) ^ (Double.doubleToLongBits(this.area) >> 32) ^ (Double.doubleToLongBits(this.area) << 32));
        return hash;
    }
    public Object clone(){
        return new Office(this.area,this.rooms);
    }
    
    public Office(){
        rooms=DEFAULT_ROOM;
        area=DEFAULT_AREA;
    }
    public Office(double s){
        try{
        if(s<=0)throw new InvalidSpaceAreaException();
        area=s;
        rooms=DEFAULT_ROOM;
        }catch(InvalidSpaceAreaException e){
            System.out.println(e);
            area=DEFAULT_AREA;
        }
    }
    public Office(double s,int n){
        try{
        area=s;
        rooms=n;
        if(s<=0)throw new InvalidSpaceAreaException();
        if(n<=0)throw new InvalidRoomsCountException();
        }catch(InvalidSpaceAreaException e){
            System.out.println(e);
            area=DEFAULT_AREA;
        }
        catch(InvalidRoomsCountException e){
            System.out.println(e);
            rooms=DEFAULT_ROOM; 
        }
    }
}
